<?php
/**
 * index.phtml
 *
 * @category    Madoqua
 * @package     Module
 * @subpackage  Feed
 */

/** zend feed */
require_once 'Zend/Feed.php';

$this->layout()->disableLayout();
//disable layouts

$config = $this->config();
//application config

$latest = $this->posts->current()->posted;
//publication date for the latest post

$data = array(
    'title' => $config->name,
    'link' => $config->url,
    'description' => 'Post overview',
    'language' => $config->datetime->locale,
    'charset' => 'utf-8',
    'lastUpdate' => $latest,
    'generator' => 'Madoqua'
);
//feed config data

foreach($this->posts as $post) {
    $data['entries'][] = array(
        'title' => $post->title,
        'link' => $config->url . $this->urlPost($post),
        'guid' => $config->url . $this->urlPost($post),
        'description' => $post->intro,
        'lastUpdate' => $post->posted
    );
}
//feed entries

$feed = Zend_Feed::importArray($data, $this->type);
//parse the feed

$header = 'Content-type: application/' . $this->type . '+xml; charset: utf-8';
Madoqua_Application::getFront()->getResponse()->setRawHeader($header);
//set proper header

echo $feed->saveXml();
//echo feed contents